package com.shigen.demo.atguigu;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author shigenfu
 * @date 2022/5/24 10:31 下午
 */

class MyThread implements Runnable {

  @Override
  public void run() {

  }
}

class MyThread2 implements Callable<Integer> {

  @Override
  public Integer call() throws Exception {
    System.out.println("callable.....");
    return 1024;
  }
}


public class CallableDemo {

  public static void main(String[] args) throws ExecutionException, InterruptedException {
    FutureTask<Integer> futureTask = new FutureTask<>(new MyThread2());

    Thread thread = new Thread(futureTask, "AAA");
    Thread thread1 = new Thread(futureTask, "BBB");

    thread.start();
    thread1.start();

    while (!futureTask.isDone()) {

    }
    // 获得callable的计算结果
    System.out.println(futureTask.get());


  }
}
